/*
 * Copyright 2009 Lukasz Wozniak
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 *
 * http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
package pl.sind.http;

import java.net.URI;

import pl.sind.blip.message.BlipMessagePart;

/**
 * Interface representing objects abstracting HTTP conectivity with blip.
 * 
 * @author Lukasz Wozniak
 * 
 */
public interface HttpConnector {

	public static final String DEFAULT_ENCODING = "utf-8";

	/**
	 * Sets default headers used in every request.
	 * 
	 * @param headers
	 */
	public void setDefaultHeaders(HttpHeader[] headers);

	/**
	 * Gets a remote resource and returns stream to it wrapped in
	 * {@link Download}.
	 * 
	 * @param headers
	 *            additional headers to use on request.
	 * @param target
	 *            uri of resource
	 * @return {@link Download}
	 */
	public Download doDownload(HttpHeader[] headers, URI target)
			throws HttpRequestException;

	/**
	 * Executes GET method.
	 * 
	 * @param headers
	 *            additional headers to use on request.
	 * @param target
	 *            uri to be called
	 * @param body
	 *            message body to be sent
	 * @return result of request
	 * @throws HttpRequestException
	 *             on connection errors
	 */
	public HttpResult doGet(HttpHeader[] headers, URI target,
			BlipMessagePart body) throws HttpRequestException;

	/**
	 * Executes POST method.
	 * 
	 * @param headers
	 *            additional headers to use on request.
	 * @param target
	 *            uri to be called
	 * @param body
	 *            message body to be sent
	 * @return result of request
	 * @throws HttpRequestException
	 *             on connection errors
	 */
	public HttpResult doPost(HttpHeader[] headers, URI target,
			BlipMessagePart body) throws HttpRequestException;

	/**
	 * Executes PUT method.
	 * 
	 * @param headers
	 *            additional headers to use on request.
	 * @param target
	 *            uri to be called
	 * @param body
	 *            message body to be sent
	 * @return result of request
	 * @throws HttpRequestException
	 *             on connection errors
	 */
	public HttpResult doPut(HttpHeader[] headers, URI target,
			BlipMessagePart body) throws HttpRequestException;

	/**
	 * Executes DELETE method.
	 * 
	 * @param headers
	 *            additional headers to use on request.
	 * @param target
	 *            uri to be called
	 * @param body
	 *            message body to be sent
	 * @return result of request
	 * @throws HttpRequestException
	 *             on connection errors
	 */
	public HttpResult doDelete(HttpHeader[] headers, URI target,
			BlipMessagePart body) throws HttpRequestException;

}
